package com.bole.controller;

import com.bole.data.Result;
import com.bole.data.ResultEnum;
import com.bole.pojo.LeavingDo;
import com.bole.service.LeaveMessageService;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

// 留言
@RestController
@RequestMapping("message")
@Api("留言接口")
public class LeaveMessageController {

    private static final Logger logger = LoggerFactory.getLogger(LeaveMessageController.class);

    @Autowired
    private LeaveMessageService leaveMessageService;

    @GetMapping("/{sellUserId}")
    public Result getMessageByUserId(@PathVariable("sellUserId") Long sellUserId) {
        try {
            List<LeavingDo> list = leaveMessageService.getMessageBySellUserId(sellUserId);
            return Result.response(ResultEnum.OK).setData(list);
        } catch (Exception e) {
            logger.error("getMessageByUserId方法异常", e);
            return Result.response(ResultEnum.FAIL);
        }
    }

    @PostMapping
    public Result saveLeavingMessage(@RequestBody LeavingDo leavingDo) {
        try {
            leaveMessageService.saveLeavingMessage(leavingDo);
            return Result.response(ResultEnum.OK);
        } catch (Exception e) {
            logger.error("saveLeavingMessage方法异常", e);
            return Result.response(ResultEnum.FAIL);
        }
    }

}
